#include <iostream>
using namespace std;
int fibonacci(int n)
{
    if (n <= 1)
    {
        return 1;
    }

    // 使用动态数组来存储中间结果
    int* fib = new int[n + 1];
    fib[0] = 0;
    fib[1] = 1;

    // 动态规划计算裴波那契数列
    for (int i = 2; i <= n; ++i)
    {
        fib[i] = fib[i - 1] + fib[i - 2];
        // cout << fib[i] << endl;
    }

    // 获取结果
    int result = fib[n];
    // 释放动态数组内存
    delete[] fib;
    return result;
}
    int main()
    {
        int n = 9;
        int res = fibonacci(n);
        cout << "\nf(" << n << ")=" << res << endl;
        return 0;
    }
